FireBird: Generator v ulozene procedure

Otázka od: Pavel Poles

18. 8. 2004 15:19

Ahoj,

lze nejak realizovat neco jako toto:

CREATE PROCEDURE NEW_PROCEDURE (
    GENNAME VARCHAR(30))
RETURNS (
    RESULT INTEGER)
AS
begin
  SELECT GEN_ID(:GENNAME, 1) FROM rdb$database INTO :RESULT;
  suspend;
end

Tzn, vygenerovat ID z generatoru, jehoz jmeno mi prijde
jako parametr procedury?

Predem dik za odpovedi

Pavel Poles

Odpovedá: Fedor 'fi0dor' Tirsel

18. 8. 2004 15:26

: Ahoj,

Zdravim,
 
: lze nejak realizovat neco jako toto:
:
: CREATE PROCEDURE NEW_PROCEDURE (
: GENNAME VARCHAR(30))
: RETURNS (
: RESULT INTEGER)
: AS
: begin
: SELECT GEN_ID(:GENNAME, 1) FROM rdb$database INTO :RESULT;
: suspend;
: end
:
: Tzn, vygenerovat ID z generatoru, jehoz jmeno mi prijde
: jako parametr procedury?

ide to cez EXECUTE STATEMENT. Vynatok z dokumentacie hovori:

EXECUTE STATEMENT <string> INTO :var1, ., :varn;

Description

Executes <string> as SQL operation, returning single data row. Only
singleton SELECT operators may be executed with this form of EXECUTE
STATEMENT.

Sample:

CREATE PROCEDURE DynamicSampleTwo (TableName VARCHAR(100))
AS
DECLARE VARIABLE Par INT;

BEGIN
EXECUTE STATEMENT 'SELECT MAX(CheckField) FROM ' || TableName INTO :Par;
IF (Par > 100) THEN
  EXCEPTION Ex_Overflow 'Overflow in ' || TableName;
END

S pozdravom...
--
Fedor 'fi0dor' Tirsel
www.fi0dor.info